package com.niit.dao.impl;

import java.util.List;

import com.niit.bean.User;
import com.niit.bean.UserInfo;
import com.niit.dao.UserInfoDao;
import com.niit.utils.DbUtil;

public class UersInfoDaoImpl implements UserInfoDao {

	private DbUtil util=new DbUtil();
	@Override
	public int add(UserInfo t) {
		String sql="insert into tb_user_info(username,nickname,photo,signature) values(?,?,?,?,?)";
		int a= util.update(sql, t.getUsername(),t.getNickname(),t.getPhoto(),t.getSignature());
		return a;
	}

	@Override
	public int delete(UserInfo t) {
		String sql="delete from tb_user_info where id=?";
		int a= util.update(sql, t.getId());
		return a;
	}

	@Override
	public int update(UserInfo t) {
		String sql="update tb_user_info set nickname=?,photo=?,signature=? where username=?";
		int a=util.update(sql,t.getNickname(),t.getPhoto(),t.getSignature(),t.getUsername());
		return a;
	}

	@Override
	public List<UserInfo> findAll(int start, int end) {
		String sql="select * from(select rownum r,tb_user_info.* from tb_user_info) a where a.r>? and a.r<=?";
		List<UserInfo> list =util.select(sql, UserInfo.class, start,end);
		return list;
	}

	@Override
	public int findTotal() {
		return 0;
	}

	@Override
	public UserInfo findByUser(User user) {
		String sql = "select * from tb_user_info where username = ?";
		List<UserInfo> list = util.select(sql, UserInfo.class, user.getUsername());
		return list.size()>0?list.get(0):null;
	}

}
